package com.sktk.keepAccount.common.web.exception;

import com.sktk.keepAccount.common.core.exception.BaseException;
import com.sktk.keepAccount.common.core.vo.Result;
import com.sktk.keepAccount.common.web.utils.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j
public class DefaultGlobalExceptionHandlerAdvice {

    @ExceptionHandler(value = {BaseException.class})
    public String baseException(BaseException ex) {
        log.error("base exception:{}", ex.getMessage());
        if (CommonUtils.isNullOrEmpty(ex.getMessage())) {
            return Result.fail(ex.getErrorType());
        }
        return Result.fail(ex.getErrorType(), ex.getMessage());
    }

}